﻿using InternetSpiderLib;
using InternetSpiderLib.Tools;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using WeChatGZHTextExtractor.BusinessCreaters;
using WeChatGZHTextExtractor.DB;
using WeChatGZHTextExtractor.Tools;

namespace WeChatGZHTextExtractor
{
    class Program
    {
        static void Main(string[] args)
        {
            //SingleCase.Set(new WxDataContext());

            var file_name = Path.GetFullPath("Config.xml");
            SingleCase.Set(new XmlConfig()).InitByFile(file_name);

            new SystemDataService().Set(PublicKey.SystemData.SEND_STATUS, PublicKey.SystemData.SEND_STATUS_WAITING);

            SceneManager scene_manager = SingleCase.Set(new SceneManager());
            SceneHelper.Init(scene_manager);

            Task.WaitAll(new List<Task>
            {
                Task.Factory.StartNew(CreateUrlBusiness),
                //Task.Factory.StartNew(CreateImageBusiness),       // 图片同步不在这里
                Task.Factory.StartNew(CreateSendDataBusiness),
            }.ToArray());

            Console.WriteLine("程序已经运行完成");
        }

        private static void CreateSendDataBusiness()
        {
            BusinessManager business_manager = new BusinessManager(1);
            BusinessHelper.InitSendData(business_manager);

            business_manager.BusinessDelay = 1000 * 2;

            business_manager.Start();
            business_manager.Wait();
        }

        private static void CreateUrlBusiness()
        {
            BusinessManager business_manager = new BusinessManager(1);
            
            BusinessHelper.InitUrl(business_manager);

            business_manager.BusinessDelay = 1000 * 20;

            business_manager.Start();
            business_manager.Wait();
        }

        private static void CreateImageBusiness()
        {
            BusinessManager business_manager = new BusinessManager(10);
            
            BusinessHelper.InitImage(business_manager);

            business_manager.BusinessDelay = 0;

            business_manager.Start();
            business_manager.Wait();
        }
    }
}
